package com.cssnj.portal.service.query;

import com.sun.javafx.scene.control.skin.VirtualFlow;
import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import io.predictech.framework.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("query12Service")
public class Query12Service extends BaseService {

    //税友数据源
    @Qualifier("fourthJdbcTemplate")
    @Autowired
    private JdbcTemplate fourthJdbcTemplate;

    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) throws SQLException, BaseException {
        if ("queryData".equals(jsonRequest.getHandleCode()))
            return queryData(jsonRequest);
        return null;
    }

    protected JsonResponse queryData(JsonRequest jsonRequest) {
        JsonResponse jsonResponse = new JsonResponse();
        String swjgdm = (String) jsonRequest.getReqData().get("swjgdm");
        List<Object> params = new ArrayList<Object>();
        params.add(swjgdm);
        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
        Map<String, Object> map;
        SqlRowSet rs = queryDao.queryForRowSet(fourthJdbcTemplate, "select a.dq_dm, a.dq_mc, a.qy_hs, a.gth_hs, a.fqydw_hs   from cx_xzxnsrhs a  where a.swjg_dm = ?  order by a.dq_dm desc", params);
        while (rs.next()) {
            map = new HashMap<String, Object>();
            map.put("dq_dm", rs.getString("dq_dm"));
            map.put("dq_mc", rs.getString("dq_mc"));
            map.put("qy_hs", rs.getString("qy_hs"));
            map.put("gth_hs", rs.getString("gth_hs"));
            map.put("fqydw_hs", rs.getString("fqydw_hs"));
            dataList.add(map);
        }
        jsonResponse.getRepData().put("data", dataList);
        return jsonResponse;
    }


}
